package com.glory.good_dark.adapter;

import android.view.View;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.good_dark.R;
import com.glory.good_dark.entity.MaterielModelEntity;

import java.util.List;

/**
 * FileName: MaterielListAdapter
 * Author: XJH
 * Date: 2020/3/18 10:39
 * Description:
 * History:
 */
public class MaterielListAdapter extends BaseQuickAdapter<MaterielModelEntity, BaseViewHolder> {
    private boolean isReplace = false;
    private OnReplaceClickListener listener;
    public MaterielListAdapter(@Nullable List<MaterielModelEntity> data,boolean isReplace) {
        super(R.layout.adapter_materiel,data);
        this.isReplace = isReplace;
    }

    @Override
    protected void convert(BaseViewHolder helper, MaterielModelEntity item) {
        helper.setGone(R.id.llMaterielLayout,isReplace);
        helper.setGone(R.id.llReplaceLayout,isReplace);
        helper.setText(R.id.tvMaterielName,item.getMaterialName());
        helper.setText(R.id.tvMaterielNum,isReplace ? item.getMAT_NO() : item.getMATERIAL_ID());
        helper.setText(R.id.tvMaterielType,item.getMaterialType());
        helper.setText(R.id.tvMaterielExpirationTime,item.getEXPIRATION_TIME());
        helper.setText(R.id.tvMaterielID,item.getMaterialID());

        helper.getView(R.id.replaceMateriel_But).setOnClickListener(v -> {
            if (listener != null){
                listener.onReplace(v,item);
            }
        });
    }

    public void setOnReplaceClickListener(OnReplaceClickListener listener){
        this.listener = listener;
    }


    public interface OnReplaceClickListener{
        void onReplace(View v,MaterielModelEntity item);
    }
}
